package com.zhida.smartcontrol.dialog.delqddialog;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.jay.tools.utils.EventBusUtils;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.mvp.MVPBaseDialogFragment;
import com.zhida.smartcontrol.dialog.addqddialog.AddGroupEvent;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author: tanjianpei
 * date: 2019/11/29 029 16:29
 * description: 删除区段
 */
public class DelQdDialogFragment extends MVPBaseDialogFragment<DelQdDialogContract.View, DelQdDialogPresenter> implements DelQdDialogContract.View {
    @BindView(R.id.tv_msg)
    TextView mTvMsg;

    private String mId;

    public static DelQdDialogFragment newInstance(String id) {
        Bundle args = new Bundle();
        args.putString("id", id);
        DelQdDialogFragment fragment = new DelQdDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.dialog_del_qd;
    }

    @Override
    protected void initDatas(Bundle savedInstanceState) {
        mId = getArguments().getString("id");
//        mTvMsg.setText("区段下没有任何设备，可删除该区段，是否确定删除区段？");
        mTvMsg.setText("是否确定删除区段？");
    }

    @OnClick({R.id.btn_confirm, R.id.btn_cancel})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_confirm:
                mPresenter.deleteGroup(mId);
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
        }
    }

    @Override
    public void onSuccess() {
        EventBusUtils.post(new AddGroupEvent());
        dismiss();
    }
}
